import org.zjx.client.SocketClient;
import org.zjx.core.SocketConfig;
import org.zjx.service.AddService;
import org.zjx.service.HelloService;

public class ClientDemo {
    public static void main(String[] args) {
        SocketConfig config = new SocketConfig();
        SocketClient client = new SocketClient(config);
        client.connect();

        client.setMessageListener(System.out::println);

        // 创建服务代理
        HelloService helloService = client.createProxy(HelloService.class);
        AddService addService = client.createProxy(AddService.class);

        long now = System.currentTimeMillis();
        // 调用远程方法
        String result = helloService.sayHello("World");
        System.out.println("RPC Result: " + result);
        System.out.println(System.currentTimeMillis() - now);

        // 测试超时方法
        try {
            String timeoutResult = helloService.sayHelloWithTimeout("Timeout", 3000);
            System.out.println("Timeout RPC Result: " + timeoutResult);
        } catch (Exception e) {
            System.err.println("Timeout RPC Error: " + e.getMessage());
        }

        now = System.currentTimeMillis();
        int sum = addService.add(5,8);
        System.out.println("Add Result: " + sum);
        System.out.println(System.currentTimeMillis() - now);

    }
}
